﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Ribbon;
using System.ComponentModel;
using System.Xml;
using OutlookCalendar.Model;
using System.Windows.Media.Effects;
using Microsoft.Windows.Controls;
using WpfLab.Controls;
using System.Windows.Xps;
//using Microsoft.Office.Core;
using System.IO;
using System.IO.Packaging;
using System.Windows.Xps.Packaging;
using System.Text.RegularExpressions;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private static string id="0";
        private static string idx = "0";
        private static string searchword = "";
        

        public MainWindow()
        {
            InitializeComponent();
            //getData();
            //Window3 st = new Window3();
           // st.Show();
           // calendar1.

            calendar1.DataContext = Functionality.appointments;
            calendar1.MouseEnter += new MouseEventHandler(day_MouseOver);

           // MessageBox.Show(Functionality.removeNr("sdzsadfds dasasf 20/7"));
        }

        
        
        private void Ribbon_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {   
  
           Ribbon rbе = (Ribbon)e.Source;
           RibbonTab rbt = (RibbonTab)rbе.SelectedItem;
           string name = rbt.Header.ToString();
           if (name.Equals("Programa"))
           {
              // this.Conta
               dataGrid1.Visibility = Visibility.Hidden;
               calendar1.Visibility = Visibility.Visible;
           }
           else
           {
               dataGrid1.Visibility = Visibility.Visible;
               calendar1.Visibility = Visibility.Hidden;
           }
           //
        }

        private void MenuItem2_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Design");
        }

        private void MenuItem1_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                id = dataGrid1.SelectedValue.ToString();
                idx = dataGrid1.SelectedIndex.ToString();
            }
            catch (Exception ex) { }
        }

        private void Button3_Click(object sender, RoutedEventArgs e)
        {
            if (!id.Equals("0"))
            {
                if (MessageBox.Show("Ar tikrai šalinti šiuos įrašus?", "Užklausa", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {

                    Functionality.DeleteFromDB(dataGrid1, searchword);
   
                    id = "0";
                }
            }
        }

        private void Button4_Click(object sender, RoutedEventArgs e)
        {
            Window1 sw = new Window1();
            if (sw.ShowDialog() == true)
            {
                searchword = sw.textBox1.Text;
                Functionality.SearchInDB(dataGrid1, searchword);
                id = "0";
            }
        }

        private void Button22_Click(object sender, RoutedEventArgs e) //nauja prog
        {
            Appointment appointment = new Appointment();
            appointment.Subject = "--Pavadinimas--";
            DateTime nd = DateTime.Now;

            //   MessageBox.Show();
            appointment.StartTime = new DateTime(nd.Year, nd.Month, nd.Day, 06, 00, 00);
            appointment.EndTime = new DateTime(nd.Year, nd.Month, nd.Day, 07, 00, 00);

            AddAppointmentWindow aaw = new AddAppointmentWindow();
            aaw.subjectTextBox.DataContext = Functionality.getDataFromArchToCombo();
            aaw.DataContext = appointment;
            aaw.subjectTextBox.Text = appointment.Subject;
            aaw.ShowDialog();

            if (aaw.DialogResult == true)
            {

                appointment.Subject = aaw.subjectTextBox.Text;
              //  appointment.Body=aww.che

                if (!appointment.StartTime.ToShortDateString().Equals(appointment.EndTime.ToShortDateString()))
                {
                    TimeSpan ts = appointment.EndTime - appointment.StartTime;
                    DateTime dtold = appointment.StartTime;
                    for (int i = 0; i <= ts.Days; i++)
                    {
                        DateTime dt = dtold + TimeSpan.FromDays(i);
                        if ((dt.DayOfWeek.Equals(DayOfWeek.Monday) && (aaw.radioButton1.IsChecked == true)) ||
                             (dt.DayOfWeek.Equals(DayOfWeek.Tuesday) && (aaw.radioButton2.IsChecked == true)) ||
                                 (dt.DayOfWeek.Equals(DayOfWeek.Wednesday) && (aaw.radioButton3.IsChecked == true)) ||
                                     (dt.DayOfWeek.Equals(DayOfWeek.Thursday) && (aaw.radioButton4.IsChecked == true)) ||
                                         (dt.DayOfWeek.Equals(DayOfWeek.Friday) && (aaw.radioButton5.IsChecked == true)) ||
                                             (dt.DayOfWeek.Equals(DayOfWeek.Sunday) && (aaw.radioButton7.IsChecked == true)) ||
                                             (dt.DayOfWeek.Equals(DayOfWeek.Saturday) && (aaw.radioButton6.IsChecked == true)))
                        {
                            appointment.StartTime = dt;
                            appointment.EndTime = new DateTime(dt.Year, dt.Month, dt.Day, appointment.EndTime.Hour, appointment.EndTime.Minute, appointment.EndTime.Second);
                           // string resultString = Regex.Match(aaw.subjectTextBox.Text, @"\d+").Value;
                            string[] resultString = Regex.Split(aaw.subjectTextBox.Text, @"\D+");
                            List<string> ls = resultString.OfType<string>().ToList();
                            ls.RemoveAll(str => String.IsNullOrEmpty(str));
                            int sr= Int32.Parse(ls[ls.Count - 1])+i;
                            string name = aaw.subjectTextBox.Text;
                            if (name.Contains("/"))
                            {
                                name = name.Split('/')[0]+sr.ToString();
                            }
                            else
                            {
                                name = name.Replace(ls[0], sr.ToString());
                            }
                            appointment.Subject = name;
                            Functionality.appointments.Add(appointment);
                            Functionality.addAppointmentToDB(appointment);
                        }
                    }
                }
                else
                {
                    Functionality.appointments.Add(appointment);
                    Functionality.addAppointmentToDB(appointment);
                }
                calendar1.DataContext = Functionality.appointments;
                calendar1.FilterAppointments();
            }
        }

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            Window2 iw = new Window2();
            Functionality.id_filmo = Functionality.getCounter(); iw.textBox42.Text = "V_" + Functionality.id_filmo; 
            if (iw.ShowDialog() == true)
            {
               Functionality.SearchInDBArch(dataGrid1, iw.textBox2.Text);
               id = "0";
            }
        }

        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            
            if (!id.Equals("0"))
            {

                Window2 iw = new Window2();
                iw.red = true;
                Functionality.updateIntoDB(iw, dataGrid1, searchword,id);
                iw.red = false;
            }
        }

        private void Button31_Click(object sender, RoutedEventArgs e)
        {
            Functionality.getDataArch(dataGrid1);
        }

        private void Button32_Click(object sender, RoutedEventArgs e)
        {
            if (!id.Equals("0"))
            {
                if (MessageBox.Show("Ar tikrai archyvuoti šiuos įrašus?", "Užklausa", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {

                    Functionality.ArchiveRecord(dataGrid1,searchword);
                    id = "0";
                }
            }
        }

        private void Button33_Click(object sender, RoutedEventArgs e)
        {
            if (!id.Equals("0"))
            {
                if (MessageBox.Show("Ar tikrai atstatyti šiuos įrašus?", "Užklausa", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {

                    Functionality.RestorefromArchive(dataGrid1, searchword);
                    id = "0";
                }
            }
        }

        private void Button34_Click(object sender, RoutedEventArgs e)
        {
            Window1 sw = new Window1();
            if (sw.ShowDialog() == true)
            {
                searchword = sw.textBox1.Text;
                Functionality.SearchInDBArch(dataGrid1, searchword);
                id = "0";
            }
        }

        private void ProgramTab_StylusEnter(object sender, StylusEventArgs e)
        {
            MessageBox.Show("aaa");
        }

        private void Calendar_AddAppointment(object sender, RoutedEventArgs e) //nauja prog
        {
            OutlookCalendar.Controls.CalendarTimeslotItem ti=(OutlookCalendar.Controls.CalendarTimeslotItem)e.OriginalSource;
            OutlookCalendar.Controls.Calendar ci = (OutlookCalendar.Controls.Calendar)e.Source;
            
            string[] times=ti.Name.Split('_');
            Appointment appointment = new Appointment();
            appointment.Subject = "--Pavadinimas--";

            string daycal = Functionality.CalendarDayOfWeek;
            DateTime cd = Functionality.GetFirstDateOfWeek(ci.CurrentDate,DayOfWeek.Monday);
            switch (daycal)
            {
                case "day":
                    cd += TimeSpan.FromDays(0);
                    break;
                case "day1":
                    cd += TimeSpan.FromDays(1);
                    break;
                case "day2":
                    cd += TimeSpan.FromDays(2);
                    break;
                case "day3":
                    cd += TimeSpan.FromDays(3);
                    break;
                case "day4":
                    cd += TimeSpan.FromDays(4);
                    break;
                case "day5":
                    cd += TimeSpan.FromDays(5);
                    break;
                case "day6":
                    cd += TimeSpan.FromDays(6);
                    break;
                default:
                    break;
            }
            DateTime nd = cd;

         //   MessageBox.Show();
            appointment.StartTime = new DateTime(nd.Year, nd.Month, nd.Day, int.Parse(times[1]), int.Parse(times[2]), 00);
            int hr = int.Parse(times[1]);
            int mn = int.Parse(times[2]);
            mn += 5;
            if (mn == 60)
            {
                hr = hr + 1;
                mn = 0;
            }
            int days = nd.Day;
            int months = nd.Month;
            int years = nd.Year;
            if (hr == 24)
            {
                hr = 0;
              //  days = (nd + TimeSpan.FromDays(1)).Day;
               // months = (nd + TimeSpan.FromDays(1)).Month;
               // years = (nd + TimeSpan.FromDays(1)).Year;
            }
            appointment.EndTime = new DateTime(years, months, days, hr, mn, 00);

            AddAppointmentWindow aaw = new AddAppointmentWindow();
            aaw.subjectTextBox.DataContext = Functionality.getDataFromArchToCombo();
            aaw.DataContext = appointment;
            aaw.subjectTextBox.Text = appointment.Subject;
            aaw.ShowDialog();
            if (aaw.DialogResult == true)
            {

                System.Data.DataRowView selrow = (System.Data.DataRowView)aaw.subjectTextBox.SelectedValue;
                string id = "null";
                try
                {
                    id = selrow.Row[2].ToString();
                }
                catch (Exception ex) { }

                string priedas="";
                if (aaw.radioButton8.IsChecked == true)
                {
                    priedas = " (tęs.)";
                }
                if (aaw.radioButton9.IsChecked == true)
                {
                    priedas = " (kart.)";
                }
                appointment.Subject = aaw.subjectTextBox.Text+priedas;
                appointment.Location = id;
                if (!appointment.StartTime.ToShortDateString().Equals(appointment.EndTime.ToShortDateString()))
                {
                    TimeSpan ts = appointment.EndTime - appointment.StartTime;
                    if ((appointment.EndTime.Hour < 6) && (appointment.StartTime.Hour > 6 ) && (ts.Days>=0))
                    {
                        ts = ts + TimeSpan.FromDays(1);
                    }
                    DateTime dtold = appointment.StartTime;
                    for (int i = 0; i <= ts.Days; i++)
                    {
                        DateTime dt = dtold + TimeSpan.FromDays(i);
                        if ((dt.DayOfWeek.Equals(DayOfWeek.Monday) && (aaw.radioButton1.IsChecked == true)) ||
                             (dt.DayOfWeek.Equals(DayOfWeek.Tuesday) && (aaw.radioButton2.IsChecked == true)) ||
                                 (dt.DayOfWeek.Equals(DayOfWeek.Wednesday) && (aaw.radioButton3.IsChecked == true)) ||
                                     (dt.DayOfWeek.Equals(DayOfWeek.Thursday) && (aaw.radioButton4.IsChecked == true)) ||
                                         (dt.DayOfWeek.Equals(DayOfWeek.Friday) && (aaw.radioButton5.IsChecked == true)) ||
                                             (dt.DayOfWeek.Equals(DayOfWeek.Sunday) && (aaw.radioButton7.IsChecked == true)) ||
                                             (dt.DayOfWeek.Equals(DayOfWeek.Saturday) && (aaw.radioButton6.IsChecked == true)))
                        {
                            appointment.StartTime = dt;
                            appointment.EndTime = new DateTime(dt.Year, dt.Month, dt.Day, appointment.EndTime.Hour, appointment.EndTime.Minute, appointment.EndTime.Second);
                            string[] resultString = Regex.Split(aaw.subjectTextBox.Text, @"\D+");
                            List<string> ls = resultString.OfType<string>().ToList();
                            ls.RemoveAll(str => String.IsNullOrEmpty(str));
                            int sr = Int32.Parse(ls[ls.Count - 1]) + i;
                            string name = aaw.subjectTextBox.Text;
                            if (name.Contains("/"))
                            {
                                name = name.Split('/')[0] + sr.ToString();
                            }
                            else
                            {
                                name = name.Replace(ls[0], sr.ToString());
                            }
                            appointment.Subject = name;
                            Functionality.appointments.Add(appointment);
                            Functionality.addAppointmentToDB(appointment);
                        }
                    }
                }
                else
                {
                    Functionality.appointments.Add(appointment);
                    Functionality.addAppointmentToDB(appointment);
                }
                // Functionality.appointments.Add(appointment);
                // Functionality.addAppointmentToDB(appointment);
                calendar1.DataContext = Functionality.appointments;
                calendar1.FilterAppointments();

                checkOverloaded(calendar1);
            }
        }

        private void checkOverloaded(OutlookCalendar.Controls.Calendar calendar1)
        {
            foreach (Appointment ap in calendar1.Appointments)
            {
                foreach (Appointment app in calendar1.Appointments)
                {
                    if ((ap.StartTime < app.StartTime) && (ap.EndTime < app.EndTime) && (ap.EndTime > app.StartTime))
                    {
                        ap.BgColor = System.Windows.Media.Brushes.Red;
                         app.BgColor = System.Windows.Media.Brushes.Red;
                    }
                }
            }
        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
           
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
             if ((Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) && (e.Key==Key.F))
            {
                Window1 fw = new Window1();
                if (fw.ShowDialog() == true)
                {
                        searchword = fw.textBox1.Text;
                    /*    dt = BuildDynamicTableArrayExample();
                        dv = new DataView(dt);
 
                       int row = dv.Find(textBox1.Text); // find the text...
                       if (row >= 0)
                       {
                           CM.Position = row; // position the row pointer...
                           dataGrid1..Select(row); // if wanting to highlight the row too...
                       }
 
                    */
                         id = "0";
                }
            }
        }

        private void Button41_Click(object sender, RoutedEventArgs e)
        {
           
        }

        private void Button42_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName = "Document"; // Default file name
            dlg.DefaultExt = ".xls"; // Default file extension
            dlg.Filter = "Excel documentai (.xls)|*.xls"; // Filter files by extension

            // Show save file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;
                try
                {
                    Office.exportToExcel(filename, dataGrid1);
                    MessageBox.Show("Exportas baigtas!");
                }
                catch (Exception ex) { MessageBox.Show("Įvyko klaida eksportuojant į Excel!"); }
            }
            //Office.convert("", dataGrid1);

            
         }

        private void Button43_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName = "Document"; // Default file name
            dlg.DefaultExt = ".docx"; // Default file extension
            dlg.Filter = "Word documentai (.docx)|*.docx"; // Filter files by extension

            // Show save file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;
                try
                {
                    Office.exportToWord(filename, dataGrid1);
                    MessageBox.Show("Exportas baigtas!");
                }
                catch (Exception ex) { MessageBox.Show("Įvyko klaida eksportuojant į Word!"); }
            }
        }

        private void Button44_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName = "Document"; // Default file name
            dlg.DefaultExt = ".pdf"; // Default file extension
            dlg.Filter = "PDF documentai (.pdf)|*.pdf"; // Filter files by extension

            // Show save file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;
                try
                {
                    Pdf.printToPDF(filename, dataGrid1);
                    MessageBox.Show("Exportas baigtas!");
                }
                catch (Exception ex) { MessageBox.Show("Įvyko klaida eksportuojant į PDF!"); }
            }
        }

        private void Button23_Click(object sender, RoutedEventArgs e) //red prog
        {
            if (Functionality.appointmentSelected != null)
            {
                Appointment appointment = new Appointment();
                appointment.Subject = Functionality.appointmentSelected.Subject;

                appointment.StartTime = Functionality.appointmentSelected.StartTime;

                appointment.EndTime = Functionality.appointmentSelected.EndTime;
                appointment.Location = Functionality.appointmentSelected.Location;

                AddAppointmentWindow aaw = new AddAppointmentWindow();
                aaw.radioButton1.Visibility = Visibility.Hidden;
                aaw.radioButton2.Visibility = Visibility.Hidden;
                aaw.radioButton3.Visibility = Visibility.Hidden;
                aaw.radioButton4.Visibility = Visibility.Hidden;
                aaw.radioButton5.Visibility = Visibility.Hidden;
                aaw.radioButton6.Visibility = Visibility.Hidden;
                aaw.radioButton7.Visibility = Visibility.Hidden;
                aaw.subjectTextBox.DataContext = Functionality.getDataFromArchToCombo();
                aaw.subjectTextBox.SelectedValue = appointment.Location;
                aaw.DataContext = appointment;
                //if (appointment.Subject.Contains(" (tęs.)")) { appointment.Subject.Replace(" (tęs.)", ""); aaw.radioButton8.IsChecked=true; }
                //if (appointment.Subject.Contains(" (kart.)")) { appointment.Subject.Replace(" (kart.)", ""); aaw.radioButton9.IsChecked = true; }
                aaw.subjectTextBox.Text = appointment.Subject;

                aaw.ShowDialog();

                if (aaw.DialogResult == true)
                {

                    System.Data.DataRowView selrow = (System.Data.DataRowView)aaw.subjectTextBox.SelectedValue;
                    string id = "null";
                    try
                    {
                        if (!appointment.Location.Equals(""))
                        {
                            id = appointment.Location;
                        }
                        id = selrow.Row[2].ToString();
                    }
                    catch (Exception ex) { }

                    string priedas = "";
                    if (aaw.radioButton8.IsChecked == true)
                    {
                        priedas = " (tęs.)";
                    }
                    if (aaw.radioButton9.IsChecked == true)
                    {
                        priedas = " (kart.)";
                    }
                    appointment.Subject = aaw.subjectTextBox.Text+priedas;
                    appointment.Location = id;
                    Functionality.appointments.Remove(Functionality.appointmentSelected);
                    Functionality.removeAppointmentFromDB(Functionality.appointmentSelected);
                    Functionality.appointments.Add(appointment);
                    Functionality.addAppointmentToDB(appointment);
                    Functionality.appointmentSelected = null;
                    calendar1.DataContext = Functionality.appointments;
                    calendar1.FilterAppointments();
                }
            }
        }

        private void Button21_Click(object sender, RoutedEventArgs e)
        {
           /* IEnumerator<Appointment> app = calendar1.Appointments.GetEnumerator();
            app.Reset();
            while (app.MoveNext())
            {
                MessageBox.Show(((Appointment)app.Current).StartTime.ToShortDateString() + "  " + ((Appointment)app.Current).StartTime.ToShortTimeString());
            }
            MessageBox.Show(calendar1.CurrentDate.ToShortDateString());*/
         /*   foreach (Appointment ap in Functionality.appointments)
            {
                MessageBox.Show(ap.Subject + " " + ap.StartTime + " " + ap.EndTime);
            }*/
        }

        private void Button24_Click(object sender, RoutedEventArgs e)
        {
            if (Functionality.appointmentSelected != null)
            {
                if (MessageBox.Show("Ar tikrai šalinti šį įvykį?", "Šalinimas", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {

                    Functionality.appointments.Remove(Functionality.appointmentSelected);
                    Functionality.removeAppointmentFromDB(Functionality.appointmentSelected);
                    calendar1.DataContext = Functionality.appointments;
                    calendar1.FilterAppointments();
                }
            }
        }

        public void openFile()
        {
            string SourceUrl = "";
           // Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            string xpsFilePath = String.Empty;
            // Set filter for file extension and default file extension 
           /* dlg.DefaultExt = ".txt";
            dlg.Filter = "Office Files(*.docx;*.doc;*.xlsx;*.xls;*.pptx;*.ppt)|*.docx;*.doc;*.xlsx;*.xls;*.pptx;*.ppt";

            // Display OpenFileDialog by calling ShowDialog method 
            Nullable<bool> result = dlg.ShowDialog();*/

            // Get the selected file name and display in a TextBox 
            //if (result == true)
           // {
                string filename = System.Environment.CurrentDirectory + "\\tempPrograma.xls";
                xpsFilePath = System.Environment.CurrentDirectory + "\\tempPrograma.xps";
                SourceUrl = filename;
           // }

         /*       var convertResults=OfficeToXps.ConvertToXps(SourceUrl, ref xpsFilePath);
            switch (convertResults.Result)
            {
                case ConversionResult.OK:
                    XpsDocument xpsDoc = new System.Windows.Xps.Packaging.XpsDocument(xpsFilePath, FileAccess.ReadWrite);
                    documentViewer1.Document = xpsDoc.GetFixedDocumentSequence();
                    bool officeFileOpen_Status = true;
                    break;

                case ConversionResult.InvalidFilePath:
                    // Handle bad file path or file missing
                    break;
                case ConversionResult.UnexpectedError:
                    // This should only happen if the code is modified poorly
                    break;
                case ConversionResult.ErrorUnableToInitializeOfficeApp:
                    // Handle Office 2007 (Word | Excel | PowerPoint) not installed
                    break;
                case ConversionResult.ErrorUnableToOpenOfficeFile:
                    // Handle source file being locked or invalid permissions
                    break;
                case ConversionResult.ErrorUnableToAccessOfficeInterop:
                    // Handle Office 2007 (Word | Excel | PowerPoint) not installed
                    break;
                case ConversionResult.ErrorUnableToExportToXps:
                    // Handle Microsoft Save As PDF or XPS Add-In missing for 2007
                    break;
            }*/
        }

        private void Button51_Click(object sender, RoutedEventArgs e)
        {
           // mp.Visibility = Visibility.Visible;
          //  WpfLab.Controls.ModalDialogPopup
            //mp.ButtonOKText = "Taip";
            //mp.ButtonCancelText = "Uždaryti";
            //mp.ShowOKButton = false;
           /* foreach (ContentControl gr in Functionality.FindVisualChildren<ContentControl>(mp))
            {
                gr.SetValue(Window.MaxWidthProperty, 20.0);
            }*/
           // dataGrid2.
        /*    int cols = 5;
int rows = 110;

for (int c = 0; c < cols; c++)
   myTable.Columns.Add(new TableColumn());

for (int r = 0; r < rows; r++)
{
   TableRow tr = new TableRow();

   for (int c = 0; c < cols; c++)
      tr.Cells.Add(new TableCell(new Paragraph(new Run("Some Text"))));

   TableRowGroup trg = new TableRowGroup();
   trg.Rows.Add(tr);
   myTable.RowGroups.Add(trg);
}*/
            openFile();
            mp.IsOpen = true;
           // ModalDialogPopup mp = new ModalDialogPopup();
           // mp.BringIntoView();
            /* BlurEffect blur = new BlurEffect();
            var current = this.Background;
            blur.Radius = 5;
            this.Background = new SolidColorBrush(Colors.DarkGray);
            this.Effect = blur;
            MessageBox.Show("hello");

            this.Effect = null;
            this.Background = current;*/
        }

        private void Button52_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName = "Programa"; // Default file name
            dlg.DefaultExt = ".xls"; // Default file extension
            dlg.Filter = "Excel documentai (.xls)|*.xls"; // Filter files by extension

            // Show save file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;
                try
                {
                    Office.exportToExcelPrograma(filename, calendar1.CurrentDate);
                    MessageBox.Show("Exportas baigtas!");
                }
                catch (Exception ex) { MessageBox.Show("Įvyko klaida eksportuojant į Excel!"); }
            }
        }

        private void Button53_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName = "Programa"; // Default file name
            dlg.DefaultExt = ".docx"; // Default file extension
            dlg.Filter = "Word documentai (.docx)|*.docx"; // Filter files by extension

            // Show save file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;
                try
                {
                    Office.exportToWordProgram(filename, calendar1.CurrentDate);
                    MessageBox.Show("Exportas baigtas!");
                }
                catch (Exception ex) { MessageBox.Show("Įvyko klaida eksportuojant į Word!"); }
            }
        }

        private void Button54_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName = "Programa"; // Default file name
            dlg.DefaultExt = ".pdf"; // Default file extension
            dlg.Filter = "PDF documentai (.pdf)|*.pdf"; // Filter files by extension

            // Show save file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;
                try
                {
                    Pdf.printToPDFPrograma(filename,calendar1.CurrentDate);
                    MessageBox.Show("Exportas baigtas!");
                }
                catch (Exception ex) { MessageBox.Show("Įvyko klaida eksportuojant į PDF!"); }
            }
        }

        public void MouseEventHandler_mg(Object sender,MouseEventArgs e)
        {
         }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
           
           
        }

        private void day_MouseOver(object sender, MouseEventArgs e)
        {
        }


    }
}
